package com.syx.spring.utils;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.MultipartFile;


public class FileUtil {
	 public static String uploadMethod(MultipartFile file, HttpServletRequest request) {  
		 	String basePath = "http://sailcloud.gicp.net:10008/logistics/";
		 	//String basePath = "http://localhost:8080/logistics/";
	        System.out.println("开始");  
	        String path = request.getSession().getServletContext().getRealPath("upload");  
	        
	        String fileName = file.getOriginalFilename();  
	        System.out.println(path);  
	        File targetFile = new File(path, fileName);  
	        if(!targetFile.exists()){  
	            targetFile.mkdirs();  
	        }  
	  
	        //保存  
	        try {  
	            file.transferTo(targetFile);  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	        System.out.println(request.getContextPath());
	        System.out.println(basePath+"upload/"+fileName);
	        String fileUrl = basePath+"upload/"+fileName;  
	        return fileUrl;  
	    }  
}
